
#ifndef __RSA_KEYPAIR_H
#define __RSA_KEYPAIR_H

#include <openssl/rsa.h>
#include "../iface/CryptInterface.h"
#include "../iface/SSLInterface.h"
#include "KeyPair.h"

// Can import from:
// database
// PKCS format
// OpenSSL generator
//
// Can export to:
// OpenSSH
// cryptlib
// database
// PKCS format
// OpenSSL

// Instead of RSA_new and RSA_free, do dynamic manipulation so that NULL can be used to check more closely
// what is really going on.

class RSAKeyPair : public KeyPair
{
   public:
      int InitialiseRSAKeyFromPublicKey(CRYPT_PKCINFO_RSA *rsaKey);
      int InitialiseRSAKeyFromPrivateKey(CRYPT_PKCINFO_RSA *rsaKey);
      CRYPT_CONTEXT GetCryptContext_PublicKey(const char *name);
      CRYPT_CONTEXT GetCryptContext_PrivateKey(const char *name);
      int GenerateKeyPair(int nbits);
      char *ExportPrivateKey();
      char *ExportPasswordedPrivateKey(const char *password);
      int ImportPrivateKey(const char *encoded);
      int ImportPasswordedPrivateKey(const char *password, const char *encoded);
      char *ExportPublicKey();
      char *ExportOpenSSHPublicKeyBlob(int *reallength);
      char *ExportOpenSSHPublicKey(const char *keylabel);
      int ImportPublicKey(const char *encoded);
      const char *GetKeyTypeName();
      char *GetMD5KeyFingerprint();
      char *GetFingerprintAsVariableName();
      static int RSACopyPublicKey(RSA *dst, RSA *src);
      static int RSACopyPrivateKey(RSA *dst, RSA *src);
      void RSAMergeKeyPair(RSAKeyPair *kpub, RSAKeyPair *kprv);
      int RSAKeyCompareThisPublicToPublic(RSAKeyPair *icmp);
      int RSAKeyCompareThisPrivateToPublic(RSAKeyPair *icmp);
      RSAKeyPair();
      ~RSAKeyPair();
      RSA *pub;
      RSA *prv;
};

#endif
